<template>
  <div class="wuxiang-modal" v-if="visible">
    <div class="wuxiang-content">
      <h2 class="wuxiang-title">🔄 发现"无相"</h2>
      
      <div class="wuxiang-info">
        <p class="wuxiang-desc">
          <span class="player-name">{{ wuxiangPlayer?.name || '某位玩家' }}</span> 
          的手牌中不包含红相、黑相、红尔、黑尔任何一张，根据游戏规则需要重新洗牌。
        </p>
      </div>

      <!-- 显示所有玩家的手牌 -->
      <div class="all-players-cards">
        <h3>各玩家手牌展示：</h3>
        <div class="players-grid">
          <div 
            v-for="player in players" 
            :key="player.id" 
            class="player-cards"
            :class="{ 'wuxiang-player': player.id === wuxiangPlayer?.id }"
          >
            <div class="player-header">
              <span class="player-icon">{{ player.emoji || '🤖' }}</span>
              <span class="player-name">{{ player.name }}</span>
              <span v-if="player.id === wuxiangPlayer?.id" class="wuxiang-tag">无相</span>
            </div>
            <div class="cards-display">
              <div 
                v-for="card in player.cards" 
                :key="card.id"
                class="mini-card"
                :class="getCardClass(card)"
              >
                <div class="card-content">
                  <span class="card-symbol">{{ card.getSymbol() }}</span>
                  <span class="card-name">{{ card.displayName }}</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 倒计时和操作 -->
      <div class="countdown-section">
        <div class="countdown-display">
          <span class="countdown-text">{{ countdown }}秒后自动重新发牌</span>
          <div class="countdown-circle">
            <svg class="progress-ring" width="60" height="60">
              <circle
                class="progress-ring-circle"
                stroke="#667eea"
                stroke-width="4"
                fill="transparent"
                r="26"
                cx="30"
                cy="30"
                :stroke-dasharray="circumference"
                :stroke-dashoffset="dashOffset"
              />
            </svg>
            <span class="countdown-number">{{ countdown }}</span>
          </div>
        </div>
        
        <button class="redeal-btn" @click="$emit('close')">
          立即重新发牌
        </button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue';

const props = defineProps({
  visible: Boolean,
  wuxiangPlayer: Object,
  players: Array,
  countdown: {
    type: Number,
    default: 5
  }
});

defineEmits(['close']);

// 计算环形进度条
const circumference = 2 * Math.PI * 26;
const dashOffset = computed(() => {
  const progress = (5 - props.countdown) / 5;
  return circumference * (1 - progress);
});

// 获取卡牌样式类
const getCardClass = (card) => {
  const classes = ['mini-card'];
  
  // 添加颜色类
  if (['hearts', 'diamonds'].includes(card.suit)) {
    classes.push('red-card');
  } else {
    classes.push('black-card');
  }
  
  // 高亮关键牌型
  if (['红相', '黑相', '红尔', '黑尔'].includes(card.displayName)) {
    classes.push('key-card');
  }
  
  return classes.join(' ');
};
</script>

<style scoped>
.wuxiang-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
}

.wuxiang-content {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 20px;
  padding: 30px;
  max-width: 800px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  color: white;
}

.wuxiang-title {
  text-align: center;
  color: white;
  margin-bottom: 20px;
  font-size: 28px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.wuxiang-info {
  text-align: center;
  margin-bottom: 25px;
}

.wuxiang-desc {
  font-size: 18px;
  line-height: 1.6;
  margin-bottom: 10px;
}

.player-name {
  color: #ffd700;
  font-weight: bold;
}

.all-players-cards h3 {
  color: white;
  margin-bottom: 15px;
  text-align: center;
}

.players-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin-bottom: 25px;
}

.player-cards {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 15px;
  padding: 15px;
  backdrop-filter: blur(10px);
}

.player-cards.wuxiang-player {
  border: 2px solid #ff6b6b;
  background: rgba(255, 107, 107, 0.2);
}

.player-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.player-icon {
  font-size: 20px;
}

.wuxiang-tag {
  background: #ff6b6b;
  color: white;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: bold;
}

.cards-display {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.mini-card {
  background: white;
  border-radius: 8px;
  padding: 6px 4px;
  text-align: center;
  min-height: 50px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  font-size: 11px;
  transition: all 0.3s ease;
}

.mini-card.red-card {
  color: #ff4444;
}

.mini-card.black-card {
  color: #333;
}

.mini-card.key-card {
  border: 2px solid #ffd700;
  background: #fffacd;
  box-shadow: 0 2px 8px rgba(255, 215, 0, 0.4);
}

.card-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.card-symbol {
  font-size: 14px;
}

.card-name {
  font-size: 10px;
  font-weight: bold;
}

.countdown-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  margin-top: 25px;
}

.countdown-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
}

.countdown-text {
  font-size: 16px;
  color: #ffd700;
}

.countdown-circle {
  position: relative;
  width: 60px;
  height: 60px;
}

.progress-ring {
  transform: rotate(-90deg);
}

.progress-ring-circle {
  transition: stroke-dashoffset 1s ease;
}

.countdown-number {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 24px;
  font-weight: bold;
  color: white;
}

.redeal-btn {
  background: linear-gradient(135deg, #ff6b6b 0%, #ff8e8e 100%);
  color: white;
  border: none;
  border-radius: 15px;
  padding: 12px 30px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(255, 107, 107, 0.4);
}

.redeal-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 107, 107, 0.6);
}

/* 响应式 */
@media (max-width: 768px) {
  .wuxiang-content {
    padding: 20px;
    margin: 10px;
  }
  
  .wuxiang-title {
    font-size: 24px;
  }
  
  .wuxiang-desc {
    font-size: 16px;
  }
  
  .players-grid {
    grid-template-columns: 1fr;
    gap: 15px;
  }
  
  .cards-display {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }
  
  .mini-card {
    min-height: 40px;
    font-size: 10px;
  }
}
</style>